//
//  GQRegisterContactCell.m
//  GuQu
//
//  Created by HELIUM STAR on 15/6/11.
//  Copyright (c) 2015年 HELIUM STAR. All rights reserved.
//

#import "GQRegisterContactCell.h"
#import "GQProfileContact.h"

@interface GQRegisterContactCell ()

@property (weak, nonatomic) UIButton *iconImage;
@property (weak, nonatomic) UIImageView *vertify;
@property (weak, nonatomic) UILabel *nameLabel;
@property (weak, nonatomic) UILabel *phoneLable;
@property (weak, nonatomic) UIButton *concernBtn;
@property (weak, nonatomic) UILabel *unknownName;

@end

@implementation GQRegisterContactCell

- (void)setPhoneInfo:(GQProfileContact *)phoneInfo
{
    
    _phoneInfo = phoneInfo;
    [self.iconImage setImage:[UIImage imageRoundWithImage:self.phoneInfo.image] forState:UIControlStateNormal];
    
    if ([_phoneInfo.isStar isEqualToString:@"1"]) {
        self.vertify.image = [UIImage imageNamed:@"relationship_famous_accreditation"];
    }else{
        self.vertify.image = [UIImage imageNamed:nil];
    }
    
    
    self.nameLabel.text = self.phoneInfo.name;
    
    NSLog(@"%d", self.phoneInfo.isIcon);
    if ([self.phoneInfo.name isEqualToString:@"未命名"]) {
        //创建认证用户
        self.unknownName.text = @"未命名";
    }
    NSLog(@"%d", self.phoneInfo.isIcon);
    if(self.phoneInfo.isIcon){
        self.unknownName.hidden = NO;
        self.unknownName.text = self.phoneInfo.name;
    }else{
        
        self.unknownName.hidden = YES;
    }
    
    if (self.phoneInfo.phoneNums) {
        self.phoneLable.text = self.phoneInfo.phoneNums[0];
    }else{
        self.phoneLable.text = @"";
    }
    
    
    self.unknownName.text = self.phoneInfo.name;
    
    if (self.phoneInfo.isReg) {
        [self.concernBtn setImage:[UIImage imageNamed:@"relationship_concern"] forState:UIControlStateNormal];
        [self.concernBtn setImage:[UIImage imageNamed:@"relationship_concerned"] forState:UIControlStateSelected];
    }else{
        [self.concernBtn setImage:nil forState:UIControlStateNormal];
        [self.concernBtn setImage:nil forState:UIControlStateSelected];
        [self.concernBtn setTitle:@"邀请" forState:UIControlStateNormal];
        [self.concernBtn setTitleColor:[UIColor colorWithRed:27/255.0 green:190/255.0 blue:179/255.0 alpha:1.0] forState:UIControlStateNormal];
        self.concernBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    }
    
    
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpChildView];
    }
    return self;
}

- (void)setUpChildView
{
    //创建头像
    UIButton *iconImage = [[UIButton alloc] init];
    self.iconImage = iconImage;
    [self addSubview:iconImage];
    
    UIImageView *vertify = [[UIImageView alloc] init];
    self.vertify = vertify;
    [iconImage addSubview:vertify];
    
    //创建姓名标签
    UILabel *nameLabel = [[UILabel alloc] init];
    nameLabel.font = [UIFont systemFontOfSize:14];
    self.nameLabel = nameLabel;
    [self addSubview:nameLabel];
    
    //创建电话标签
    UILabel *phoneLable = [[UILabel alloc] init];
    phoneLable.font = [UIFont systemFontOfSize:12];
    phoneLable.textColor = [UIColor lightGrayColor];
    self.phoneLable = phoneLable;
    [self addSubview:phoneLable];
    
    //创建姓名标签
    UILabel *unknownName = [[UILabel alloc] init];
    unknownName.font = [UIFont systemFontOfSize:12];
    unknownName.textAlignment = NSTextAlignmentCenter;
    unknownName.textColor = [UIColor whiteColor];
    [self.iconImage addSubview:unknownName];
    self.unknownName = unknownName;
    
    UIButton *concernBtn = [[UIButton alloc] init];
    [concernBtn addTarget:self action:@selector(concernBtnDidClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:concernBtn];
    self.concernBtn = concernBtn;
}

- (void)concernBtnDidClick:(UIButton *)btn
{
    btn.selected = !btn.selected;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat iconWidth = 40;
    CGFloat vertifyWidth = 15;
    CGFloat concernMargin = 15;
    CGFloat concernWidth = 57;
    CGFloat concernHeight = 25;
    
    self.iconImage.frame = CGRectMake(10, 10, iconWidth, iconWidth);
    
    self.unknownName.x = 0;
    self.unknownName.width = self.iconImage.width;
    self.unknownName.height = 12;
    self.unknownName.y = (self.iconImage.height - self.unknownName.height) / 2;
    
    self.vertify.x = self.iconImage.width - vertifyWidth;
    self.vertify.y = self.iconImage.height - vertifyWidth;
    self.vertify.width = vertifyWidth;
    self.vertify.height = vertifyWidth;
    
    self.nameLabel.frame = CGRectMake(CGRectGetMaxX(self.iconImage.frame) + 20, CGRectGetMinX(self.iconImage.frame) + 5, 200, 18);
    self.phoneLable.frame = CGRectMake(self.nameLabel.x, CGRectGetMaxY(self.nameLabel.frame), 200, 18);
    self.concernBtn.frame = CGRectMake(self.width - concernMargin - concernWidth, (self.height - concernHeight) / 2, concernWidth, concernHeight);
    
}

@end
